package com.facotry.service.Impl;

import com.facotry.entity.FacUser;
import com.facotry.entity.ProduceWorkOrder;
import com.facotry.mapper.ProduceWorkOrderMapper;
import com.facotry.service.ProduceWorkOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

/**
 * ------ 天道酬勤 -------
 *
 * @author ChenZihao
 * @date 2024/7/25
 * @desc --- 代码敲烂 月薪过万 ---
 */


@Service
public class ProduceWorkOrderServiceImp implements ProduceWorkOrderService {
    @Autowired
    private ProduceWorkOrderMapper produceWorkOrderMapper;


    @Override
    public List<ProduceWorkOrder> findAll(HashMap<String, String> map) {
        // System.out.println("业务层map = " + map);
        // long startNum = Long.parseLong(map.get("startNum"));
        // System.out.println("startNum = " + startNum);
        // long overNum = Long.parseLong(map.get("overNum"));
        // java.sql.Date date1 = new java.sql.Date(startNum);
        // System.out.println("date1 = " + date1);


        List<ProduceWorkOrder> list =  produceWorkOrderMapper.findAll(map);
        return list;
    }

    @Override
    public boolean addProduceWorkOrder(ProduceWorkOrder produceWorkOrder) {
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        FacUser info = (FacUser) request.getSession().getAttribute("userInfo");
        String username = info.getUsername();
        produceWorkOrder.setCreater(username);
        produceWorkOrder.setCreateTime(new Date());

        boolean isOk = produceWorkOrderMapper.addProduceWorkOrder(produceWorkOrder);
        return isOk;
    }

    @Override
    public boolean delBatchWorkOrders(List<String> ids) {
        boolean isOk = produceWorkOrderMapper.delBatchWorkOrders(ids);
        return isOk;
    }

    @Override
    public boolean workOrderDown(ProduceWorkOrder produceWorkOrder) {
        boolean isOk = produceWorkOrderMapper.workOrderDown(produceWorkOrder);
        return isOk;
    }

    @Override
    public boolean workOrderStop(ProduceWorkOrder produceWorkOrder) {
        boolean isOk = produceWorkOrderMapper.workOrderStop(produceWorkOrder);
        return isOk;
    }

    @Override
    public boolean workOrderClose(ProduceWorkOrder produceWorkOrder) {
        boolean isOk = produceWorkOrderMapper.workOrderClose(produceWorkOrder);

        return isOk;
    }
}
